package com.app.newiptv.presenter;

import android.os.Bundle;

import com.app.newiptv.bean.Content;
import com.app.newiptv.bean.SearchResultBean;
import com.app.newiptv.bean.details.PlayDetailsBean;
import com.app.newiptv.callback.RequestCallback;
import com.app.newiptv.service.AHservice;
import com.app.newiptv.utils.APPLog;

import java.util.List;

/**
 * Created by wendal on 2017/9/17.
 */

public class ExitPresenter {
    private boolean isDisplayed;
    private Callback callback;
    private List<Content> listContent;
    private List<Content> vodContent;
    private AHservice service;
    private List<SearchResultBean.DataBean.ListBean> playDetailsBeanList;

    public interface Callback {
        void onError(int code, String msg);

        void onRecommendCompleted(ExitPresenter presenter, int count);
    }

    public interface ItemViewHolder {
        void setItemName(String name);

        void setImageUrl(String url);
    }

    public void setCallback(Callback callback) {
        this.callback = callback;
    }

    public void setDisplayed(boolean displayed) {
        isDisplayed = displayed;
    }

    public void loadVodItem(String url, int postion) {
        service = new AHservice();
        service.playDetailItemCallback(url, new ItemLoadCallback());
    }

    public void onBindMovieView(ItemViewHolder holder, int position) {
        if (!isDisplayed) {
            return;
        }
        if (playDetailsBeanList != null && position < playDetailsBeanList.size()) {
            holder.setImageUrl(playDetailsBeanList.get(position).getVod_pic());
            holder.setItemName(playDetailsBeanList.get(position).getVod_name());
        }
    }
    public Bundle getParams(int position) {
        Bundle bundle = new Bundle();
        SearchResultBean.DataBean.ListBean playDetailsBean = playDetailsBeanList.get(position);
        bundle.putInt("id", Integer.valueOf(playDetailsBean.getVod_id()));
        return bundle;
    }

    public boolean getVodType(int position) {
        SearchResultBean.DataBean.ListBean playDetailsBean = playDetailsBeanList.get(position);
        if (Integer.valueOf(playDetailsBean.getType_pid()) == 1) {
            return true;
        }
        return false;
    }

    public boolean getTelType(int position) {
        SearchResultBean.DataBean.ListBean playDetailsBean = playDetailsBeanList.get(position);
        if (Integer.valueOf(playDetailsBean.getType_pid()) > 1) {
            return true;
        }
        return false;
    }
    class ItemLoadCallback implements RequestCallback {
        @Override
        public void onFailed(String arg0, String arg1) {

        }

        @Override
        public void onLoadComplete(String contentID, int pageNumber, int count, List contents) {
            if (callback == null || !isDisplayed) {
                APPLog.printInfo("onLoadComplete:callback :");
                return;
            }
            playDetailsBeanList = contents;
            callback.onRecommendCompleted(ExitPresenter.this, count);
        }

        @Override
        public void onLoading(String arg0) {
        }
    }
}
